#ifndef MPHTTPGENERICCONNECTION_H
#define MPHTTPGENERICCONNECTION_H

#include "mpRandomUtils.h"
#include "mpHttpConnection.h"

namespace MP{
namespace HTTP{
namespace INTERNAL{

class HttpGenericConnection : public HttpConnection
{
public:
    HttpGenericConnection(boost::asio::io_context& io_context);
    ~HttpGenericConnection() override = default;

public:
    //设置或读取最近一次使用HttpConnection的时间
    void setLastUseTime(time_t clock) override;
    time_t getLastUseTime() const override;

    void setPoolKey(const std::string& poolKey) override;
    //返回连接在Pool中对应的Key
    const std::string& getPoolKey() const override;
    //返回连接ID，Connection的唯一标识
    const std::string& getId() const override;

    HttpSocket& getHttpSocket() override;

    //    void preConnect(const std::string & host) override;

    void handshakeAsync(func_handshake_callback&& handler) override;

    void writeSomeAsync(const std::vector<boost::asio::const_buffer>& buffers,
                        func_write_callback&& handler) override;

    //    void readUntilAsync(std::string & input_buffer,
    //                        const std::string & delim,
    //                        func_read_callback&& handler) override;

    void readSomeAsync(const boost::asio::mutable_buffer& buffers,
                       func_read_callback&& handler) override;

    //    void readUntilAsync(boost::asio::streambuf & buffers,
    //                        const std::string & delim,
    //                        func_read_callback&& handler) override;

    //    void readSomeAsync(boost::asio::streambuf & buffers,
    //                       func_read_callback&& handler) override;

    //取消当前操作
    void cancle() override;
    //设置已连接
    void changeToConnect() override;
    //断开连接
    void disConnected() override;
    //返回连接是否已连接上
    bool isConnected() override;

    //是否为HTTPS加密连接
    bool isSsl() const override;

private:
    //boost::asio::io_context& _io_context;
    boost::asio::ip::tcp::socket _socket;
    bool _connected;

    std::string _id;
    std::string _poolKey;
    std::time_t _lastUseTime = std::time(NULL);
};


}   //INTERNAL
}   //HTTP
}   //MP




#endif // MPHTTPGENERICCONNECTION_H
